package com.hafiery.sdk.bluetooth.test;

import android.app.Application;
import android.content.Context;
import android.text.TextUtils;
import com.hafiery.sdk.bluetooth.BlueToothActionImp;
import com.hafiery.sdk.bluetooth.api.BlueToothSDK;
import com.tencent.bugly.crashreport.CrashReport;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.UUID;

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        Context context = getApplicationContext();
        String packageName = context.getPackageName();
        String processName = getProcessName(android.os.Process.myPid());
        CrashReport.UserStrategy strategy = new CrashReport.UserStrategy(context);
        strategy.setUploadProcess(processName == null || processName.equals(packageName));
        CrashReport.initCrashReport(getApplicationContext(), "3f951c5ee4", false);
//        BlueToothSDK.init(new BlueToothActionImp(this,
//                UUID.fromString("000000ff-0000-1000-8000-00805f9b34fb"),
//                UUID.fromString("0000ff01-0000-1000-8000-00805f9b34fb"),
//                UUID.fromString("0000ff01-0000-1000-8000-00805f9b34fb"),
//                UUID.fromString("0000ff01-0000-1000-8000-00805f9b34fb")));
//        BlueToothSDK.init(new BlueToothActionImp(this,
//                UUID.fromString("0000b3ff-0000-1000-8000-00805f9b34fb"),
//                UUID.fromString("0000d6c9-0000-1000-8000-00805f9b34fb"),
//                UUID.fromString("0000d6c9-0000-1000-8000-00805f9b34fb"),
//                UUID.fromString("0000d1c9-0000-1000-8000-00805f9b34fb")));
    }
    private static String getProcessName(int pid) {
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader("/proc/" + pid + "/cmdline"));
            String processName = reader.readLine();
            if (!TextUtils.isEmpty(processName)) {
                processName = processName.trim();
            }
            return processName;
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        } finally {
            try {
                if (reader != null) {
                    reader.close();
                }
            } catch (IOException exception) {
                exception.printStackTrace();
            }
        }
        return null;
    }
}
